package com.grad.webstudy.controller;

import com.github.pagehelper.PageInfo;
import com.grad.webstudy.annota.LoginAuthorization;
import com.grad.webstudy.service.CourseCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: zjf
 * @Date: 2020/2/15 17:12.
 */

@RestController
@RequestMapping("/comment")
public class CommentController {


    @Autowired
    private CourseCommentService courseCommentService;


    @PostMapping("/add")
    public boolean add(String content, Integer detailId) {
        return courseCommentService.addComment(content, detailId);
    }


    @LoginAuthorization
    @DeleteMapping("/delete")
    public boolean deleteIds(String ids, @RequestParam(defaultValue = "false") boolean isAdminDo) {
        return courseCommentService.deleteByIds(ids, isAdminDo);
    }


    @GetMapping("/queryByDetailId")
    public PageInfo queryByDetailId(Integer detailId
            , @RequestParam(defaultValue = "1") Integer currPage
            , @RequestParam(defaultValue = "5") Integer pageSize) {
        return courseCommentService.queryByDetailId(detailId, currPage, pageSize);
    }


    @GetMapping("/queryAll")
    public PageInfo queryAll(@RequestParam(defaultValue = "1") Integer currPage
            , @RequestParam(defaultValue = "5") Integer pageSize) {

        return courseCommentService.queryAll(currPage, pageSize);
    }
}
